package com.plian.system.controller.transfer;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.plian.system.config.AppKeySign;
import com.plian.system.dto.transfer.DataPlatSign;
import com.plian.system.entity.fr.bank.BankKey;
import com.plian.system.model.R;
import com.plian.system.model.token.PassToken;
import com.plian.system.service.fr.bank.IBankKeyService;
import com.plian.system.service.transfer.IGrantSalaryTransferService;
import com.plian.system.vo.pf.BaseGrantSalaryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "api/grantsalarytransfer")
@Api(value = "职工工资数据对接", tags = "职工工资数据对接")
public class GrantSalaryTransferController {

    @Autowired
    private IGrantSalaryTransferService grantSalaryTransferService;

    @Autowired
    private IBankKeyService bankKeyService;

    @PostMapping(value = "/submit-grant-salary-list")
    @ApiOperation(value = "职工工资数据 批量", notes = "传入projectInfoVOS")
    public R submitGrantSalaryList(@RequestBody List<BaseGrantSalaryVO> baseGrantSalaryVOS){
        return grantSalaryTransferService.submitGrantSalaryList(baseGrantSalaryVOS);
    }

    @PostMapping(value = "/list-by-top-org-id")
    @PassToken
    @AppKeySign
    public R<List<BaseGrantSalaryVO>> listByTopOrgId(@RequestBody DataPlatSign dataPlatSign){
        String appId = dataPlatSign.getAppId();
        BankKey bankKey = bankKeyService.getOne(Wrappers.<BankKey>lambdaQuery().eq(BankKey::getAppId, appId));
        String topGroupId = bankKey.getTopGroupId();
        return R.data(grantSalaryTransferService.listByTopOrgId(topGroupId));
    }
}
